//
//  DBParserRuleNamed.m
//  parser
//
//  Created by Daniel Braun on 26/05/07.
//  Copyright 2007 __MyCompanyName__. All rights reserved.
//

#import "DBParserRuleNamed.h"
#import "DBParser.h"
#import "DBLexer.h"
#import "DBParserRuleNamedInst.h"

@implementation DBParserRuleNamed

- (void) dealloc {
	[name release];
	[super dealloc];
}

- (NSString *) name
{
	return name;
}
- (void) setRuleName:(NSString *)s
{
	[name release];
	name=[s retain];
}


- (void) invokeWithParser:(DBParser *)p
{
	NSAssert(0, @"should be instanciated");
}
- (void) preProcess
{
	NSAssert(0, @"should be instanciated");
}
- (int *) tokens
{
	NSAssert(0, @"should be instanciated");
	return nil;
}

- (DBParserRule *) instantiateRule
{
	return [DBParserRuleNamedInst instRuleWith:self];
}
+ (id) ruleNamed:(NSString *)name action:(SEL) act rule:(DBParserRule *)r1,... 
{
	va_list ap;
	DBParserRuleNamed *rul=[[[[self class]alloc]initWithAction:(SEL)act]autorelease];
	if (!rul) return nil;
	[rul setRuleName:name];
	[rul appendSeq: [r1 instantiateRule]];
	va_start(ap, r1);
	for (;;) {
		DBParserRule *r;
		r=va_arg(ap, DBParserRule *);
		if (!r) break;
		[rul appendSeq:[r instantiateRule]];
	}
	va_end(ap);
	return rul;
}
- (NSString *) description
{
	return [NSString stringWithFormat:@"rule definition \"%@\"",name];
}


@end
